﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Data.Transform
{
	public sealed class TransformMap : ITransformMap, ITransformMapInfo
	{
		private readonly List<TransformPropertyMap> properties = new List<TransformPropertyMap>();
		private readonly ITransformService transformService;

		public TransformMap(ITransformService transformService)
		{
			this.transformService = transformService;
		}

		ITransformMap ITransformMap.IsLooseTransform(bool isLoose)
		{
			IsLooseTransform = isLoose;

			return this;
		}

		ITransformMap ITransformMap.InType(Type inType)
		{
			InType = inType;

			return this;
		}

		ITransformMap ITransformMap.OutType(Type outType)
		{
			OutType = outType;

			return this;
		}

		public ITransformPropertyMap MapProperty
		{
			get
			{
				TransformPropertyMap returnValue = new TransformPropertyMap
					                                   {
						                                   TransformMap = this
					                                   };

				properties.Add(returnValue);

				return returnValue;
			}
		}

		public void MapComplete()
		{
			transformService.AddTransforms(this);
		}

		public bool IsLooseTransform { get; private set; }

		public Type InType { get; private set; }

		public Type OutType { get; private set; }

		public IEnumerable<ITransformPropertyMapInfo> MappedProperties()
		{
			return new List<ITransformPropertyMapInfo>(properties);
		}
	}
}